/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.nii.qlks.GUI;

import edu.nii.qlks.ControlLayer.PhongControl;
import edu.nii.qlks.DataTransferObject.PhongInfo;
import java.awt.Color;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author KUUT
 */
public class JInternal_Lapdanhmucphong extends javax.swing.JInternalFrame {

    PhongInfo phong_info;
    PhongControl phong_control;
    Vector table_record;
    Vector table_title;
    
    public JInternal_Lapdanhmucphong() throws Exception {
        initComponents();
        float[] color = new float[3];
        color = Color.RGBtoHSB(255,255,255,color);
        this.getContentPane().setBackground(Color.getHSBColor(color[0], color[1], color[2]));
        
        phong_control = new PhongControl();
        phong_info = new PhongInfo();
        
        table_record = new Vector();
        table_title = new Vector();
        
        table_title.add("STT");
        table_title.add("Tên phòng");
        table_title.add("Tên loại phòng");
        table_title.add("Đơn giá");
        table_title.add("Tình trạng");
        table_title.add("Ghi chú");
        
        //Mẫu cho combobox
        jComboBox_Tenloaiphong.setModel(new DefaultComboBoxModel(phong_control.LayTenLoaiPhong()));
        jComboBox_Tenloaiphong.setSelectedIndex(-1);
        loadDSPhong();
        //Hiện item đầu tiên.
    }

    public void loadDSPhong() throws Exception{
        table_record = phong_control.LayDanhSachPhong();
        jXTable_Danhsachphong.setModel(new DefaultTableModel(table_record, table_title));
    }
    
    public boolean trungTenPhong(String s){
        for (int i = 0; i < jXTable_Danhsachphong.getRowCount(); i++) {
            if(s.equals(jXTable_Danhsachphong.getValueAt(i, 1).toString().trim()))
                return true;
        }
        return false;
    }
    
    public boolean CheckSpecial(String s) throws Exception{
        Pattern p = Pattern.compile("[^a-z 0-9 ]", Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(s);
        boolean b = m.find();

        if (b){
           return true;
        }
        else{ 
            return false;
        }
    }
    
    public void clear(){
        jXTextField_Tenphong.setText(null);
        jXTextField_Maphong.setText(null);
        jXTextField_Ghichu.setText(null);
        jXTextField_Dongiaphong.setText(null);
    }
    
    public void huy(){
        jXButton_Them.setIcon(new ImageIcon(getClass().getResource("/icon/icon/remove.png"))); // NOI18N
        jXButton_Them.setText("HUỶ");
        kiemTraThem = huy;
    }
    
    public void them(){
        jXButton_Them.setIcon(new ImageIcon(getClass().getResource("/icon/icon/add.png"))); // NOI18N
        jXButton_Them.setText("THÊM");
        kiemTraThem = them;
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXPanel2 = new org.jdesktop.swingx.JXPanel();
        jXLabel7 = new org.jdesktop.swingx.JXLabel();
        jXPanel3 = new org.jdesktop.swingx.JXPanel();
        jXLabel1 = new org.jdesktop.swingx.JXLabel();
        jXLabel2 = new org.jdesktop.swingx.JXLabel();
        jXLabel3 = new org.jdesktop.swingx.JXLabel();
        jXLabel4 = new org.jdesktop.swingx.JXLabel();
        jXLabel5 = new org.jdesktop.swingx.JXLabel();
        jXLabel6 = new org.jdesktop.swingx.JXLabel();
        jXTextField_Tenphong = new org.jdesktop.swingx.JXTextField();
        jXTextField_Maphong = new org.jdesktop.swingx.JXTextField();
        jXTextField_Dongiaphong = new org.jdesktop.swingx.JXTextField();
        jXTextField_Ghichu = new org.jdesktop.swingx.JXTextField();
        jXButton_Them = new org.jdesktop.swingx.JXButton();
        jComboBox_Tenloaiphong = new javax.swing.JComboBox();
        jXTextField_Tinhtrang = new org.jdesktop.swingx.JXTextField();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jXTable_Danhsachphong = new org.jdesktop.swingx.JXTable();
        jXButton_Sua = new org.jdesktop.swingx.JXButton();
        jXButton_Xoa = new org.jdesktop.swingx.JXButton();
        jXButton_Thoat = new org.jdesktop.swingx.JXButton();

        setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        jXPanel2.setBackground(new java.awt.Color(0, 51, 204));

        jXLabel7.setForeground(new java.awt.Color(255, 255, 255));
        jXLabel7.setText("LẬP DANH MỤC PHÒNG");
        jXLabel7.setFont(new java.awt.Font("Times New Roman", 1, 36)); // NOI18N

        javax.swing.GroupLayout jXPanel2Layout = new javax.swing.GroupLayout(jXPanel2);
        jXPanel2.setLayout(jXPanel2Layout);
        jXPanel2Layout.setHorizontalGroup(
            jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jXLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(222, 222, 222))
        );
        jXPanel2Layout.setVerticalGroup(
            jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel2Layout.createSequentialGroup()
                .addContainerGap(14, Short.MAX_VALUE)
                .addComponent(jXLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jXPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jXPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông tin phòng", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 18), new java.awt.Color(255, 0, 0))); // NOI18N

        jXLabel1.setText("Tên loại phòng");

        jXLabel2.setText("Tên phòng");

        jXLabel3.setText("Mã phòng");

        jXLabel4.setText("Tình trạng");

        jXLabel5.setText("Đơn giá phòng");

        jXLabel6.setText("Ghi chú");

        jXTextField_Tenphong.setToolTipText("Ví dụ: 109");
        jXTextField_Tenphong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXTextField_TenphongActionPerformed(evt);
            }
        });
        jXTextField_Tenphong.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jXTextField_TenphongKeyReleased(evt);
            }
        });

        jXTextField_Maphong.setToolTipText("Ví dụ:  A109");
        jXTextField_Maphong.setDisabledTextColor(new java.awt.Color(255, 0, 0));
        jXTextField_Maphong.setEnabled(false);

        jXTextField_Dongiaphong.setDisabledTextColor(new java.awt.Color(255, 0, 0));
        jXTextField_Dongiaphong.setEnabled(false);

        jXButton_Them.setBackground(new java.awt.Color(0, 51, 204));
        jXButton_Them.setForeground(new java.awt.Color(255, 255, 255));
        jXButton_Them.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/icon/add.png"))); // NOI18N
        jXButton_Them.setText("THÊM");
        jXButton_Them.setBorderPainted(false);
        jXButton_Them.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXButton_ThemActionPerformed(evt);
            }
        });

        jComboBox_Tenloaiphong.setBackground(new java.awt.Color(255, 249, 156));
        jComboBox_Tenloaiphong.setEditable(true);
        jComboBox_Tenloaiphong.setMaximumRowCount(9);
        jComboBox_Tenloaiphong.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox_Tenloaiphong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox_TenloaiphongActionPerformed(evt);
            }
        });

        jXTextField_Tinhtrang.setText("0");
        jXTextField_Tinhtrang.setDisabledTextColor(new java.awt.Color(255, 0, 0));
        jXTextField_Tinhtrang.setEnabled(false);

        javax.swing.GroupLayout jXPanel3Layout = new javax.swing.GroupLayout(jXPanel3);
        jXPanel3.setLayout(jXPanel3Layout);
        jXPanel3Layout.setHorizontalGroup(
            jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel3Layout.createSequentialGroup()
                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jXPanel3Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jXButton_Them, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jXPanel3Layout.createSequentialGroup()
                        .addGap(120, 120, 120)
                        .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jXLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jXLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jXLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jXPanel3Layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jXTextField_Tenphong, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jXTextField_Maphong, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jXPanel3Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jComboBox_Tenloaiphong, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 75, Short.MAX_VALUE)
                        .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jXLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jXLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jXLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jXTextField_Dongiaphong, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jXTextField_Ghichu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jXTextField_Tinhtrang, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(158, 158, 158))
        );
        jXPanel3Layout.setVerticalGroup(
            jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jXLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox_Tenloaiphong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXTextField_Tinhtrang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jXLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXTextField_Tenphong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXTextField_Dongiaphong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanel3Layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jXLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jXTextField_Maphong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jXPanel3Layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jXLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jXTextField_Ghichu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jXButton_Them, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jXPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jXPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Danh sách phòng", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 18), new java.awt.Color(255, 0, 0))); // NOI18N

        jXTable_Danhsachphong.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jXTable_Danhsachphong);

        javax.swing.GroupLayout jXPanel1Layout = new javax.swing.GroupLayout(jXPanel1);
        jXPanel1.setLayout(jXPanel1Layout);
        jXPanel1Layout.setHorizontalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2)
        );
        jXPanel1Layout.setVerticalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
        );

        jXButton_Sua.setBackground(new java.awt.Color(0, 51, 204));
        jXButton_Sua.setForeground(new java.awt.Color(255, 255, 255));
        jXButton_Sua.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/icon/edit.png"))); // NOI18N
        jXButton_Sua.setText("SỬA");
        jXButton_Sua.setBorderPainted(false);
        jXButton_Sua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXButton_SuaActionPerformed(evt);
            }
        });

        jXButton_Xoa.setBackground(new java.awt.Color(0, 51, 204));
        jXButton_Xoa.setForeground(new java.awt.Color(255, 255, 255));
        jXButton_Xoa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/icon/remove.png"))); // NOI18N
        jXButton_Xoa.setText("XOÁ");
        jXButton_Xoa.setBorderPainted(false);
        jXButton_Xoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXButton_XoaActionPerformed(evt);
            }
        });

        jXButton_Thoat.setBackground(new java.awt.Color(0, 51, 204));
        jXButton_Thoat.setForeground(new java.awt.Color(255, 255, 255));
        jXButton_Thoat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/icon/exit.png"))); // NOI18N
        jXButton_Thoat.setText("THOÁT");
        jXButton_Thoat.setBorderPainted(false);
        jXButton_Thoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXButton_ThoatActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jXPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jXButton_Sua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(jXButton_Xoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jXButton_Thoat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(112, 112, 112))
            .addGroup(layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jXPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jXPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(43, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jXPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jXPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jXButton_Sua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXButton_Xoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXButton_Thoat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jXTextField_TenphongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXTextField_TenphongActionPerformed
        jXTextField_Maphong.setText("" +
            jComboBox_Tenloaiphong.getSelectedItem().toString().trim() + jXTextField_Tenphong.getText());
    }//GEN-LAST:event_jXTextField_TenphongActionPerformed

    private void jXTextField_TenphongKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jXTextField_TenphongKeyReleased

        if(jXTextField_Tenphong.getText().length() > 10){
            JOptionPane.showMessageDialog(null, "Tên phòng quá độ dài cho phép."
                , "Thông tin", JOptionPane.INFORMATION_MESSAGE);
            clear();
            return;
        }
        if(jComboBox_Tenloaiphong.getSelectedIndex() < 0){
            jXTextField_Maphong.setText(jXTextField_Tenphong.getText());
        }
        else{
            jXTextField_Maphong.setText("" +
                jComboBox_Tenloaiphong.getSelectedItem().toString().trim() + jXTextField_Tenphong.getText());
        }

        try{
            if(CheckSpecial(jXTextField_Tenphong.getText())){
                JOptionPane.showMessageDialog(null, "Tên phòng không được có kí tự đặc biệt!"
                    , "Thông tin", JOptionPane.INFORMATION_MESSAGE);
            }
        }catch(Exception e){}

    }//GEN-LAST:event_jXTextField_TenphongKeyReleased

    private void jXButton_ThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXButton_ThemActionPerformed

        if(kiemTraThem == them){

            if(jComboBox_Tenloaiphong.getSelectedIndex() < 0){
                JOptionPane.showMessageDialog(null, "Vui lòng chọn Tên Loại Phòng"
                    , "Warning", JOptionPane.WARNING_MESSAGE);
                return;
            }
            //Kiểm tra tên phòng và mã phòng có để trống hay không
            if(jXTextField_Maphong.getText().equals("")
                || jXTextField_Tenphong.getText().equals("")){
                JOptionPane.showMessageDialog(null, "Không được để trống Tên phòng"
                    , "Warning", JOptionPane.WARNING_MESSAGE);
                return;
            }

            try{
                //Kiem tra trung ten phong
                if(trungTenPhong(jXTextField_Tenphong.getText())){
                    JOptionPane.showMessageDialog(null, "Trùng với tên phòng khác, Vui lòng chọn tên khác"
                        , "Thông tin", JOptionPane.INFORMATION_MESSAGE);
                    return;
                }

                String[] s = phong_control.ChuyenTenLP_MaLoaiPhong(
                    jComboBox_Tenloaiphong.getSelectedItem().toString().trim());
                phong_info.setMaLoaiPhong(s[0]);
                phong_info.setTenPhong(jXTextField_Tenphong.getText().trim());
                phong_info.setMaPhong(jXTextField_Maphong.getText().trim());
                phong_info.setTinhTrangPhong(false);
                phong_info.setGhiChu(jXTextField_Ghichu.getText().trim());
                phong_control.Insert(phong_info);

                loadDSPhong();

            }catch(Exception e){

            }
        }
        else if(kiemTraThem == huy){
            jXTable_Danhsachphong.setSelectionMode(0);
            them();
            clear();
        }

    }//GEN-LAST:event_jXButton_ThemActionPerformed

    private void jComboBox_TenloaiphongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox_TenloaiphongActionPerformed

        try{
            //Lấy đơn giá phòng
            String[] s = phong_control.LayDonGia(
                jComboBox_Tenloaiphong.getSelectedItem().toString().trim());
            phong_info.setMaLoaiPhong(s[0]);
            jXTextField_Dongiaphong.setText(phong_info.getMaLoaiPhong());

            //Hiện Tên loại phòng ở Mã phòng
            jXTextField_Maphong.setText("" +
                jComboBox_Tenloaiphong.getSelectedItem().toString().trim() + jXTextField_Tenphong.getText());
        }catch(Exception e){

        }
    }//GEN-LAST:event_jComboBox_TenloaiphongActionPerformed

    private void jXButton_SuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXButton_SuaActionPerformed
        //Kiem tra da click vao Bảng chưa
        if(jXTable_Danhsachphong.getSelectedRow() < 0){
            JOptionPane.showMessageDialog(null, "Vui lòng chọn Tên Phòng trong bảng danh sách"
                , "Thông tin", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        //Kiểm tra tên phòng có trống hay không
        if(jXTextField_Maphong.getText().equals("")
            || jXTextField_Tenphong.getText().equals("")){
            JOptionPane.showMessageDialog(null, "Không được để trống Tên phòng"
                , "Warning", JOptionPane.WARNING_MESSAGE);
            return;
        }

        if(jComboBox_Tenloaiphong.getSelectedIndex() < 0){
            JOptionPane.showMessageDialog(null, "Vui lòng chọn Tên Loại Phòng"
                , "Warning", JOptionPane.WARNING_MESSAGE);
            return;
        }

        //Kiem tra trung ten phong
        String tenphong = jXTable_Danhsachphong.getValueAt(row, 1).toString().trim();
        if(trungTenPhong(jXTextField_Tenphong.getText()) && !jXTextField_Tenphong.getText().equals(tenphong)){
            JOptionPane.showMessageDialog(null, "Trùng với tên phòng khác, Vui lòng chọn tên khác"
                , "Thông tin", JOptionPane.INFORMATION_MESSAGE);
            return;
        }

        //Hỏi bạn có muốn sửa hay không
        Object option[] = {"Có", "Không"};
        if(JOptionPane.showOptionDialog(null, " Bạn có muốn sửa phòng "
            + jXTable_Danhsachphong.getValueAt(row, 1).toString()
            , "Cảnh báo", JOptionPane.YES_NO_CANCEL_OPTION
            , JOptionPane.QUESTION_MESSAGE, null, option, option[1]) == 0){

        try{
            //Lấy Mã loại phòng từ tên loại phòng
            String[] s1 = phong_control.ChuyenTenLP_MaLoaiPhong(
                jComboBox_Tenloaiphong.getSelectedItem().toString().trim());
            phong_info.setMaLoaiPhong(s1[0]);
            //Lấy Mã phòng từ Tên phòng
            String[] s = phong_control.ChuyenTenPhong_MaPhong(
                jXTable_Danhsachphong.getValueAt(row, 1).toString().trim());
            phong_info.setMaPhong(s[0].trim());
            phong_info.setTenPhong(jXTextField_Tenphong.getText().trim());
            phong_info.setTinhTrangPhong(false);
            phong_info.setGhiChu(jXTextField_Ghichu.getText().trim());

            phong_control.Update(phong_info);
            loadDSPhong();
            jXButton_Them.setEnabled(true);
            clear();

        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Lỗi sửa phòng"
                , "Thông tin", JOptionPane.INFORMATION_MESSAGE);
        }
        }

    }//GEN-LAST:event_jXButton_SuaActionPerformed

    private void jXButton_XoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXButton_XoaActionPerformed

        if(jXTable_Danhsachphong.getSelectedRow() < 0){
            JOptionPane.showMessageDialog(null, "Vui lòng kích các dòng trong bảng Danh sách phòng"
                , "Thông tin", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        //Kiem tra phòng có người dùng chưa.
        if(jXTable_Danhsachphong.getValueAt(row, 4).toString().trim().equals("1")){
            JOptionPane.showMessageDialog(null, "Phòng đang có người dùng, không được sửa"
                , "Thông tin", JOptionPane.INFORMATION_MESSAGE);
            return;
        }

        Object option[] = {"Có", "Không"};
        if(JOptionPane.showOptionDialog(null, " Bạn có muốn xoá phong "
            + jXTable_Danhsachphong.getValueAt(row, 1).toString()
            , "Cảnh báo", JOptionPane.YES_NO_CANCEL_OPTION
            , JOptionPane.QUESTION_MESSAGE, null, option, option[1]) == 0){

        try{
            String s = "" + jXTable_Danhsachphong.getValueAt(row, 1);
            String[] maphong = phong_control.ChuyenTenPhong_MaPhong(s);
            phong_info.setMaPhong(maphong[0]);
            //Xoá phòng theo mã phòng đã chọn
            phong_control.Delete(phong_info);
            loadDSPhong();
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Lỗi xoá phòng"
                , "Thông tin", JOptionPane.INFORMATION_MESSAGE);
        }
        }

    }//GEN-LAST:event_jXButton_XoaActionPerformed

    private void jXButton_ThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXButton_ThoatActionPerformed
        this.setVisible(false);
        this.removeNotify();
    }//GEN-LAST:event_jXButton_ThoatActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JComboBox jComboBox_Tenloaiphong;
    private javax.swing.JScrollPane jScrollPane2;
    private org.jdesktop.swingx.JXButton jXButton_Sua;
    private org.jdesktop.swingx.JXButton jXButton_Them;
    private org.jdesktop.swingx.JXButton jXButton_Thoat;
    private org.jdesktop.swingx.JXButton jXButton_Xoa;
    private org.jdesktop.swingx.JXLabel jXLabel1;
    private org.jdesktop.swingx.JXLabel jXLabel2;
    private org.jdesktop.swingx.JXLabel jXLabel3;
    private org.jdesktop.swingx.JXLabel jXLabel4;
    private org.jdesktop.swingx.JXLabel jXLabel5;
    private org.jdesktop.swingx.JXLabel jXLabel6;
    private org.jdesktop.swingx.JXLabel jXLabel7;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXPanel jXPanel2;
    private org.jdesktop.swingx.JXPanel jXPanel3;
    private org.jdesktop.swingx.JXTable jXTable_Danhsachphong;
    private org.jdesktop.swingx.JXTextField jXTextField_Dongiaphong;
    private org.jdesktop.swingx.JXTextField jXTextField_Ghichu;
    private org.jdesktop.swingx.JXTextField jXTextField_Maphong;
    private org.jdesktop.swingx.JXTextField jXTextField_Tenphong;
    private org.jdesktop.swingx.JXTextField jXTextField_Tinhtrang;
    // End of variables declaration//GEN-END:variables

    private static int row;
    private static int kiemTraThem = 1;
    static int them = 1;
    static int huy = 2;
}
